﻿using LitJson;
using LNet;
using OestsCommon.Model;
using OestsServer.Net;
using System.Collections.Generic;

namespace OestsServer.Handlers.OESPHandlers
{
    /// <summary>
    /// 获取在线账号
    /// </summary>
    public class GetOnlineUsersHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey
        {
            get
            {
                return PacketKey.GetOnlineUsers;
            }
        }


        public override void Execute(OESPClientChannel client, Request packet)
        {
            ResponsePacket = new Response(packet);

            List<IpUser> list = ServerController.Instance.GetOnlineUsers();
            ResponsePacket.DataObject = list;
            client.Send(ResponsePacket);
        }
    }


    /// <summary>
    /// 接收到管理员的下线某个账号请求
    /// </summary>
    public class AdminAccountOfflineHandler : HandlerBase<OESPClientChannel>
    {
        public override PacketKey PKey
        {
            get
            {
                return PacketKey.AdminAccountOffline;
            }
        }

        public override void Execute(OESPClientChannel client, Request packet)
        {
            base.Execute(client, packet);
            User user = JsonMapper.ToObject<User>(packet.DataStr);
            ServerController.Instance.ForceOfflineUser(user.DBid);
            ResponsePacket.ReturnCode = ReturnCode.Success;
            ResponsePacket.DataObject = user;
            client.Send(ResponsePacket);
        }
    }

}